package org.aurora.model.type;

import java.util.HashMap;
import java.util.Map;

public enum TaskType {
    UNKNOWN(0, "未知"), CRON(1, "cron任务"), FIXED_RATE(2, "固定频率"), FIXED_DELAY(3, "固定延迟");

    private static final Map<Integer, TaskType> VALUES_MAP = new HashMap<>();

    static {
        for (TaskType value : values()) {
            VALUES_MAP.put(value.code, value);
        }
    }

    private final int code;

    private final String desc;

    TaskType(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return this.code;
    }

    public String getDesc() {
        return desc;
    }

    public static TaskType getByCode(Integer code) {
        return VALUES_MAP.getOrDefault(code, UNKNOWN);
    }
}
